package com.example.test.gallery;

import com.example.test.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class ImageAdapter extends BaseAdapter {
	int mGalleryItemBackground;
	private Context mContext;

	private Integer[] mImageIds = { R.drawable.aaa, R.drawable.bbb,
			R.drawable.ccc, R.drawable.ddd, R.drawable.eee, R.drawable.fff };

	public ImageAdapter(Context mContext) {
		this.mContext = mContext;
		TypedArray a = mContext.obtainStyledAttributes(R.styleable.GalleryA);
		mGalleryItemBackground = a.getResourceId(
				R.styleable.GalleryA_android_galleryItemBackground, 0);
		a.recycle();
	}

	@Override
	public int getCount() {
		return mImageIds.length;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView = new ImageView(mContext);
		imageView.setImageResource(mImageIds[position]);
		imageView.setLayoutParams(new LayoutParams(150, 100));
		imageView.setScaleType(ScaleType.FIT_XY);
		imageView.setBackgroundResource(mGalleryItemBackground);
		return imageView;
	}

}
